//
//  AppointmentShootViewController.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 9/19/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "AppointmentShootViewController.h"

#import "AppointmentPhotographerViewController.h"

#import "APPointmentHospitalViewController.h"

#import "AppointmentShangMenViewController.h"

#import "SenceCell.h"

@interface AppointmentShootViewController ()
{
    NSArray * selectbgcolorArray;
    NSArray * selecttextColorArray;
    
    NSIndexPath * selectIndexPath;
    SenceCell * selectCell;
}
@end

@implementation AppointmentShootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [mTableView deselectRowAtIndexPath:selectIndexPath animated:NO];
    selectCell.contentLB.textColor =UIColorFromRGB(0x7c7c7c);
    selectCell.titleLB.textColor = UIColorFromRGB(0x6e6e6e);

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"预约摄影";

    dataArray = [[NSMutableArray alloc] init];
    
    selectbgcolorArray = @[UIColorFromRGB(0xf46979),UIColorFromRGB(0x42aeec),UIColorFromRGB(0xe8c63d),UIColorFromRGB(0x81c234),UIColorFromRGB(0xba2ef4),UIColorFromRGB(0xe0ce38),UIColorFromRGB(0x4bbabc)];
    selecttextColorArray = @[UIColorFromRGB(0xffd7dc),UIColorFromRGB(0xc3e9ff),UIColorFromRGB(0xfff3c0),UIColorFromRGB(0xe2ffc0),UIColorFromRGB(0xedc2ff),UIColorFromRGB(0xfffbd6),UIColorFromRGB(0xcaffff)];
        
    mTableView = [[UITableView alloc] initWithFrame:self.contentView.bounds style:UITableViewStylePlain];
    mTableView.delegate =self;
    mTableView.dataSource = self;
    mTableView.backgroundColor = mClearColor;
    mTableView.showsVerticalScrollIndicator =NO;
    mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.contentView addSubview:mTableView];
    
    [self getSceneDatas];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 154/2.0f;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellName = @"cell";
    SenceCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell == nil){
        cell = [[SenceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
    }
    cell.headIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"changjin0%d",indexPath.row+1]];
    
    cell.dataDict = [dataArray objectAtIndex:indexPath.row];
    cell.selectBg.backgroundColor = [selectbgcolorArray objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    SenceCell * cell = (SenceCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.contentLB.textColor = [selecttextColorArray objectAtIndex:indexPath.row];
    cell.titleLB.textColor = [UIColor whiteColor];
    
    selectCell = cell;
    selectIndexPath = indexPath;
}

-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SenceCell * cell = (SenceCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.contentLB.textColor = [selecttextColorArray objectAtIndex:indexPath.row];
    cell.titleLB.textColor = [UIColor whiteColor];
    selectCell = cell;
    selectIndexPath = indexPath;
    
    
    NSDictionary * dict = [dataArray objectAtIndex:indexPath.row];
    
    if ([dict[@"PageType"] intValue]==1){     //出生照，医院
        
        APPointmentHospitalViewController * hospitalVC = [[APPointmentHospitalViewController alloc] init];
        hospitalVC.hostpitalArray = dict[@"PhotoMode"];
        hospitalVC.SceneID = dict[@"SceneID"];
        [self.navigationController pushViewController:hospitalVC animated:YES];
        
    }else if ([dict[@"PageType"] intValue]==2){ //新生儿照，上门
        AppointmentShangMenViewController * shangmenVC = [[AppointmentShangMenViewController alloc] init];
        shangmenVC.SceneID = dict[@"SceneID"];
        shangmenVC.pmid = [dict[@"PhotoMode"] firstObject][@"PMID"];
        shangmenVC.comeSuperVC = YES;
        [self.navigationController pushViewController:shangmenVC animated:YES];
    
    }else if ([dict[@"PageType"] intValue]==5){  //上门和影棚
        
        AppointmentPhotographerViewController * pvc = [[AppointmentPhotographerViewController alloc] init];
        pvc.SceneID = dict[@"SceneID"];
        for (NSDictionary * mdict in dict[@"PhotoMode"]){
            if ([mdict[@"Cate"] intValue]==0){          //上门拍摄
                pvc.pmid = mdict[@"PMID"];
            }else if ([mdict[@"Cate"] intValue]==2){    //影棚拍摄
                pvc.pyid = mdict[@"PMID"];
            }
        }
        pvc.comeSuperVC = YES;
        [self.navigationController pushViewController:pvc animated:YES];
    }
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    selectCell.contentLB.textColor =UIColorFromRGB(0x7c7c7c);
    selectCell.titleLB.textColor = UIColorFromRGB(0x6e6e6e);
}

#pragma mark
#pragma mark  获取场景信息
-(void)getSceneDatas
{
    if(![XDTools NetworkReachable]){
        mTableView.hidden = YES;
        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    ASIHTTPRequest * request = [XDTools postRequestWithDict:@{@"Type":@"1"} API:scene_info];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [dataArray removeAllObjects];
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            mTableView.hidden = NO;
            [dataArray addObjectsFromArray:tmpDict[@"data"]];
        }else{
            mTableView.hidden = YES;
            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
        [mTableView reloadData];
    }];
    [request setFailedBlock:^{
        mTableView.hidden = YES;
        [XDTools hideProgress:self.contentView];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
